
#include "file_reload_timer.h"

#include "mmap_file.h"
#include "base/logging.h"

void FileReloadTimer::Start() {
  timer_.expires_from_now(boost::posix_time::seconds(interval_));
  timer_.async_wait(
      boost::bind(
        &FileReloadTimer::Handle,
        shared_from_this(),
        boost::asio::placeholders::error
        )
      );
}

void FileReloadTimer::Handle(const boost::system::error_code& error) {
  if (error) {
    LOG_WARN("FileReloadTimer error " << error.message());
    return;
  }

  // LOG_INFO("FileReloadTimer reload.");
  MMapFileCache::Instance().Reload();

  timer_.expires_from_now(boost::posix_time::seconds(interval_));
  timer_.async_wait(
      boost::bind(
        &FileReloadTimer::Handle,
        shared_from_this(),
        boost::asio::placeholders::error
        )
      );
}

